'use strict';
const {getDefaultModelConfig} = require("../../utils/common");
// 月度比价表
module.exports = app => {
    const { STRING, INTEGER, BIGINT, DATE, TEXT } = app.Sequelize;
    const MonthlyBidding = app.model.define(
        'MonthlyBidding',
        {
            id: { type: BIGINT, primaryKey: true, autoIncrement: true },
            month: { type: STRING(7), allowNull: false, comment: '比价月份 YYYY-MM' },
            title: { type: STRING(255), allowNull: false, comment: '比价标题' },
            description: { type: TEXT, comment: '比价描述' },
            bidding_start_date: { type: DATE, allowNull: true, comment: '比价开始日期' },
            bidding_end_date: { type: DATE, allowNull: true, comment: '比价结束日期' },
            status: { type: INTEGER, defaultValue: 1, comment: '状态 1:进行中 2:已结束 3:已确定供应商' },
            selected_supplier_id: { type: BIGINT, comment: '选中的供应商ID' },
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'monthly_bidding',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
    MonthlyBidding.associate = function () {
        // 关联官方参考价格明细
        MonthlyBidding.hasMany(app.model.Business.Dish, { foreignKey: 'monthly_bidding_id', targetKey: 'id', as: 'dishList' });
        // 关联比较供应商表
        MonthlyBidding.hasMany(app.model.Business.BiddingSupplier, { foreignKey: 'monthly_bidding_id', targetKey: 'id', as: 'biddingSupplierList' });
        // selected_supplier_id
        MonthlyBidding.belongsTo(app.model.Business.Supplier, { foreignKey: 'selected_supplier_id', targetKey: 'id', as: 'supplier' });
    };
    return MonthlyBidding
}; 
